package com.changli02.filestream;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class fileStream {
    @Test
    public void test() {
        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            fis = new FileInputStream("D:\\后端\\File_ioStream\\home.jpg");
            fos = new FileOutputStream("D:\\后端\\File_ioStream\\home1.jpg");

            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = fis.read(buffer))!=-1){
                fos.write(buffer,0,len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if(fos!=null)
                    fis.close();

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            try {
                if(fis!=null)
                    fos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }



    }
}
